package com.icodingedu.springcloud.controller;

import com.icodingedu.springcloud.entity.MessageBean;
import com.icodingedu.springcloud.topic.GroupProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class MessageController {

    @Autowired
    private GroupProducer groupProducer;

    @PostMapping("/sendgroup")
    public void sendGroupMessage(@RequestParam("body") String body){
        MessageBean messageBean = MessageBean.builder().payload(body).build();
        groupProducer.output().send(MessageBuilder.withPayload(messageBean).build());
    }

    @GetMapping("/test")
    public String test(){
        return "test";
    }
}
